package com.student.education.service.impl;

import com.student.education.dao.ClasssDao;
import com.student.education.entity.Clazz;
import com.student.education.service.ClazzService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service("clazzService")
public class ClazzServiceImpl implements ClazzService {
    @Resource
    private ClasssDao classsDao;

    @Override
    public List<Clazz> queryAll(Clazz vo) {
        return classsDao.queryAll(vo);
    }

    @Override
    public int delete(Integer id) {
        return classsDao.delete(id);
    }

    @Override
    public int update(Clazz vo) {
        return classsDao.update(vo);
    }

    @Override
    public int add(Clazz vo) {
        String nameVo = vo.getName();   //根据传进来的vo,得到name
        int k = 0;
        List<Clazz> list = classsDao.querynameVo(nameVo);  //再根据name去数据库查是否已经存在
        for (int i = 0; i < list.size(); i++) {
            k++;
        }
        if (Objects.equals(k, 0)) {  //i=0,数据库中不存在
            int j = classsDao.add(vo);  //则需要添加
            return j;
        }
        return 0;


//        return classsDao.add(vo);
    }
}
